import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:zootix/models/zt_block.model.dart';
import 'package:zootix/store/zt_block.store.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/widgets/zt_empty.dart';
import 'package:zootix/widgets/zt_fade_in_cache_image.dart';

class ZtMineBlockPage extends StatelessWidget {
  const ZtMineBlockPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => SmartRefresher(
        enablePullDown: true,
        controller: ZtBlockStore.to.refreshController,
        onRefresh: () {
          ZtBlockStore.to.getBlockList();
        },
        child: ZtBlockStore.to.blockList.isEmpty
            ? ZtEmpty()
            : ListView.builder(
                itemCount: ZtBlockStore.to.blockList.length,
                itemBuilder: (_, index) =>
                    _buildBlockItem(ZtBlockStore.to.blockList[index], index))));
  }

  Widget _buildBlockItem(ZtBlockModel item, int index) {
    return Container(
      padding: EdgeInsets.symmetric(
          vertical: ZtScreenAdaper.height(20),
          horizontal: ZtScreenAdaper.width(20)),
      child: Row(children: [
        Container(
          clipBehavior: Clip.hardEdge,
          decoration: const BoxDecoration(
            shape: BoxShape.circle,
          ),
          width: ZtScreenAdaper.width(50),
          child: ZtFadeInCacheImage(
            width: ZtScreenAdaper.width(50),
            url: item.avatar ?? '',
          ),
        ),
        SizedBox(
          width: ZtScreenAdaper.width(15),
        ),
        Expanded(
            child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              item.nickName!,
              maxLines: 2,
              style: TextStyle(
                  overflow: TextOverflow.ellipsis,
                  fontSize: ZtScreenAdaper.sp(16),
                  fontWeight: FontWeight.w500),
            ),
            Text(
              '${item.age} ${item.registerCountry ?? ''}',
              style: TextStyle(
                  fontSize: ZtScreenAdaper.sp(16),
                  color: Color(0xFF000000).withOpacity(0.4)),
            )
          ],
        )),
        SizedBox(
          width: ZtScreenAdaper.width(10),
        ),
        InkWell(
          onTap: () {
            ZtBlockStore.to.unblock(item.broadcasterId!, index);
          },
          child: Container(
            padding: EdgeInsets.symmetric(
                horizontal: ZtScreenAdaper.width(10),
                vertical: ZtScreenAdaper.height(10)),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(ZtScreenAdaper.sp(20)),
                color: const Color(0xFF454545)),
            child: Text(
              'Unblock',
              style: TextStyle(
                  fontSize: ZtScreenAdaper.sp(16), color: Colors.white),
            ),
          ),
        )
      ]),
    );
  }
}
